unit U_MasrafMerkeziTree;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ADODB, StdCtrls, Buttons, ExtCtrls,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, siComp;

type
  TfmMasrafMerkeziTree = class(TForm)
    cxgrid1: TcxGrid;
    cxgrid1DBTableView1: TcxGridDBTableView;
    cxgrid1DBTableView1MASKODU: TcxGridDBColumn;
    cxgrid1DBTableView1MASACIKLAMA: TcxGridDBColumn;
    cxgrid1Level1: TcxGridLevel;
    pnl_alt: TPanel;
    BitBtn1: TBitBtn;
    DSListe: TDataSource;
    adoListe: TADOQuery;
    adoTemp: TADOQuery;
    cxgrid1DBTableView1ID: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure cxgrid1DBTableView1DblClick(Sender: TObject);
    procedure cxgrid1DBTableView1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure cxgrid1DBTableView1ColumnHeaderClick(
      Sender: TcxGridTableView; AColumn: TcxGridColumn);
  private
    { Private declarations }
  public
    Kodtext:string;
    ACKtext:string;
  end;

var
  fmMasrafMerkeziTree: TfmMasrafMerkeziTree;

implementation

uses ana1;

{$R *.dfm}

procedure TfmMasrafMerkeziTree.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=cafree;
  fmMasrafMerkeziTree:=nil;
end;

procedure TfmMasrafMerkeziTree.BitBtn1Click(Sender: TObject);
begin
  ModalResult:=mrCancel;
  close;
end;

procedure TfmMasrafMerkeziTree.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=27 then close;
end;

procedure TfmMasrafMerkeziTree.FormCreate(Sender: TObject);
begin
  adoListe.close;
  adoListe.SQL.Text:='select * from  CS_MUH_MASRAF_MERKEZI where AKTIF = 1 order by MASKODU';
  adoListe.Open;

  Kodtext:='';
  ACKtext:='';
end;

procedure TfmMasrafMerkeziTree.cxgrid1DBTableView1DblClick(
  Sender: TObject);
begin
 anaform.MODALRESULT[1]:=adoListe.Fieldbyname('ID').asinteger;
 anaform.MODALRESULT[2]:=adoListe.Fieldbyname('MASKODU').asstring;
 anaform.MODALRESULT[3]:=adoListe.Fieldbyname('MASACIKLAMA').asstring;
 ModalResult:=mrOk;
end;

procedure TfmMasrafMerkeziTree.cxgrid1DBTableView1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
 if key=13 then begin

 anaform.MODALRESULT[1]:=adoListe.Fieldbyname('ID').asinteger;
 anaform.MODALRESULT[2]:=adoListe.Fieldbyname('MASKODU').asstring;
 anaform.MODALRESULT[3]:=adoListe.Fieldbyname('MASACIKLAMA').asstring;
 ModalResult:=mrOk;
 //close;

   end;
end;

procedure TfmMasrafMerkeziTree.FormShow(Sender: TObject);
begin
//
  if Kodtext <> '' then begin
  adotemp.close;
  adotemp.sql.text:='select * from CS_MUH_MASRAF_MERKEZI where AKTIF=1 and MASKODU like :DD order by MASKODU';
  adotemp.Parameters.ParamByName('DD').Value:= KodText + '%' ;
  adoTemp.Open;
  if adotemp.RecordCount >0 then
     adoListe.Locate('MASKODU', adotemp.fieldbyname('MASKODU').Value ,[] );

  end;


  if ACKtext <> '' then begin
  adotemp.close;
  adotemp.sql.text:='select * from CS_MUH_MASRAF_MERKEZI where AKTIF=1 and MASACIKLAMA like :DD order by MASACIKLAMA';
  adotemp.Parameters.ParamByName('DD').Value:= AckText + '%'  ;
  adoTemp.Open;
  if adotemp.RecordCount >0 then
     adoListe.Locate('MASACIKLAMA', adotemp.fieldbyname('MASACIKLAMA').Value ,[] );

  end;
end;

procedure TfmMasrafMerkeziTree.cxgrid1DBTableView1ColumnHeaderClick(
  Sender: TcxGridTableView; AColumn: TcxGridColumn);
begin
 If AColumn.SortOrder = soAscending Then
  Begin
    adoListe.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' DESC'
  End
  Else
  Begin
    adoListe.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' ASC';
  End;

  cxgrid1DBTableView1.OptionsBehavior.IncSearchItem := AColumn;
end;

end.